package com.ruoyi.reviews.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.reviews.domain.ReviewsName;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.reviews.mapper.ReviewsMapper;
import com.ruoyi.reviews.domain.Reviews;
import com.ruoyi.reviews.service.IReviewsService;

/**
 * 评论Service业务层处理
 * 
 * @author sqlstudent
 * @date 2025-06-12
 */
@Service
public class ReviewsServiceImpl implements IReviewsService 
{
    @Autowired
    private ReviewsMapper reviewsMapper;
    @Autowired
    ISysUserService sysUserService;

    /**
     * 查询评论
     * 
     * @param reviewId 评论主键
     * @return 评论
     */
    @Override
    public Reviews selectReviewsByReviewId(Long reviewId)
    {
        return reviewsMapper.selectReviewsByReviewId(reviewId);
    }

    /**
     * 查询评论列表
     * 
     * @param reviews 评论
     * @return 评论
     */
    @Override
    public List<Reviews> selectReviewsList(Reviews reviews)
    {
        return reviewsMapper.selectReviewsList(reviews);
    }


    @Override
    public List<ReviewsName> selectReviewsListName(Reviews reviews) {
        List<Reviews> list=new ArrayList<>();
        List<ReviewsName> listName=new ArrayList<>();
        list=reviewsMapper.selectReviewsList(reviews);
         for(Reviews i:list){
             ReviewsName reviewsName=new ReviewsName();
             reviewsName.setReviewId(i.getReviewId());
             reviewsName.setUserName(i.getUserName());
             reviewsName.setProductId(i.getProductId());
             reviewsName.setRating(i.getRating());
             reviewsName.setComment(i.getComment());
             reviewsName.setReviewDate(i.getReviewDate());

             listName.add(reviewsName);

         }
         return listName;
    }
    /**
     * 新增评论
     * 
     * @param reviews 评论
     * @return 结果
     */
    @Override
    public int insertReviews(Reviews reviews)
    {
        return reviewsMapper.insertReviews(reviews);
    }

    /**
     * 修改评论
     * 
     * @param reviews 评论
     * @return 结果
     */
    @Override
    public int updateReviews(Reviews reviews)
    {
        return reviewsMapper.updateReviews(reviews);
    }

    /**
     * 批量删除评论
     * 
     * @param reviewIds 需要删除的评论主键
     * @return 结果
     */
    @Override
    public int deleteReviewsByReviewIds(Long[] reviewIds)
    {
        return reviewsMapper.deleteReviewsByReviewIds(reviewIds);
    }

    /**
     * 删除评论信息
     * 
     * @param reviewId 评论主键
     * @return 结果
     */
    @Override
    public int deleteReviewsByReviewId(Long reviewId)
    {
        return reviewsMapper.deleteReviewsByReviewId(reviewId);
    }
}
